//
//  HWHomeHttpManager.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/24.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit
import Alamofire
import HandyJSON
@objc class HWHomeHttpManager: NSObject {
    var uid = HWLocallyStoredData.getLoginUserID()
    var tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
    var p = 1
    var max_p = "1"
}

extension HWHomeHttpManager {
    /// sign加密
    /// - Returns: sign
    func encrySign() -> String {
        
        let sign = "\(uid)\(tStr)\("fsd213ewdsadqwe2121213edsad")"
        let signMD5 = WMUtil.md5HexDigest(sign) ?? ""
        return signMD5
    }
    func headers() -> HTTPHeaders {
//        let tStr = Date().timeStamp
//        let signature = "nnmitu"+tStr
//
//        let json = ["usersid":HWLocallyData.getUsersID(),"timestamp":tStr,"signature":signature.DDMD5Encrypt(.lowercase32)]
//        let jsonString = HWPublicFuncTools.convertDictionAryToJson(dic: json as NSDictionary)
//        let aesStr:String = aesEncryptString(jsonString, "NrrynIXcpucYvGSk")
        let header:HTTPHeaders = ["eaua":JJUUIDManager.getUUID(),"imei":ASIdentifierManager.shared().advertisingIdentifier.uuidString]
        
        return header
    }
}

extension HWHomeHttpManager {
    
    @objc func getBaseUrl(success:@escaping (_ urlString:String) -> Void, failure:@escaping(_ errorStr:String)->Void){
        let parameters  = [
            "author":APP_Author,
        ]
        AF.request(URL(string: URL_GetBaseUrl)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    success(result)
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 首页标签
    /// - Parameters:
    ///   - success: model
    ///   - failure: error
    func getHomeConfig(success:@escaping (_ :HWHomeConfigModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_HomeConfig)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? String == "1" {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWHomeConfigModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }
                        
                    } else if resultDic["code"] as? String == "100" {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    failure("没有获取到数据")
                    print("没有获取到数据")
                    
                }
                
            }else {
                failure("获取数据失败")
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    func getHomeInfo(type:String,success:@escaping (_ :HWHomeModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "member_id":HWLocallyStoredData.getCode(),
            "ios":"1",
            "type":type
        ] as [String : Any]
        
        AF.request(URL(string: URL_Home)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWHomeModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                failure("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    /// 首页弹窗
    /// - Parameters:
    ///   - success: model
    ///   - failure: error
    func getHomeAlert(success:@escaping (_ :HWHomeAlertModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode()
        ] as [String : Any]
        
        AF.request(URL(string: URL_HomeAlert)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = HWHomeAlertModel.deserialize(from: result ,designatedPath: ".data") {
                            print(model)
                            success(model)
                            
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    func gameCloseGroup(groupId:String,success:@escaping (_ :Bool) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "id":groupId
        ] as [String : Any]
        
        AF.request(URL(string: URL_CloseGameGroup)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    func scanLoginAuth(token:String,success:@escaping (_ :Bool) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "token":token
        ] as [String : Any]
        
        AF.request(URL(string: URL_ScanLogin)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                
                let result:String = responses.value ?? ""
                if result != "" {
                    
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        
                        
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        success(true)
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                    
                }else {
                    print("没有获取到数据")
                    
                }
                
            }else {
                print("获取数据失败")
                //                self.p -= 1
            }
        }
    }
    
    //MARK: 新增
    /// 资讯分类
    func getHomeInfoCate(success:@escaping (_ :[HWHomeInfoCateModel]) -> Void, failure:@escaping(_ :String)->Void){
        let parameters  = [
            "ct":"news",
            "ac":"classs",
        ]
        AF.request(URL(string: URL_HomeInfomation)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let model = [HWHomeInfoCateModel].deserialize(from: result ,designatedPath: ".data") {
                            success(model as! [HWHomeInfoCateModel])
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 资讯列表
    func getHomeInfoList(class_id:Int,p:Int,success:@escaping (_ :HWHomeInfoModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "ct":"news",
            "class_id":class_id,
            "p":p
        ] as [String : Any]
        AF.request(URL(string: URL_HomeInfomation)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        let dataModel = HWHomeInfoModel()
                        if let itemModel = [HWHomeInfoItemModel].deserialize(from: result ,designatedPath: ".data") {
                            dataModel.infoData = itemModel as? [HWHomeInfoItemModel]
                        }
                        if let bannerModel = [HWHomeInfoBannerModel].deserialize(from: result ,designatedPath: ".banners") {
                            dataModel.banners = bannerModel as? [HWHomeInfoBannerModel]
                        }
                        success(dataModel)
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 资讯详情
    func getHomeInfoDetail(id:Int,success:@escaping (_ :HWHomeInfoDetailModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "ct":"news",
            "ac":"info",
            "id":id
        ] as [String : Any]
        AF.request(URL(string: URL_HomeInfomation)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        let dataModel = HWHomeInfoDetailModel()
                        if let itemModel = HWHomeInfoDetailDataModel.deserialize(from: result ,designatedPath: ".data") {
                            dataModel.data = itemModel
                        }
                        if let authorModel = HWHomeInfoDetailAuthorModel.deserialize(from: result ,designatedPath: ".author") {
                            dataModel.author = authorModel
                        }
                        if let gameModel = HWHomeInfoDetailGameModel.deserialize(from: result ,designatedPath: ".game") {
                            dataModel.game = gameModel
                        }
                        if let yqwModel = [HWHomeInfoDetailGameModel].deserialize(from: result ,designatedPath: ".game_yqw") {
                            dataModel.game_yqw = yqwModel as? [HWHomeInfoDetailGameModel]
                        }
                        success(dataModel)
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 首页黑神话
    func getHomeWuKong(page: Int,success:@escaping (_ :HWWuKongHotChatModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "p":p
        ] as [String : Any]
        
        AF.request(URL(string: URL_HomeWuKong)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        let dataModel = HWWuKongHotChatModel()
                        if let itemModel = [HWWuKongDataModel].deserialize(from: result ,designatedPath: ".data") {
                            dataModel.data = itemModel as? [HWWuKongDataModel]
                        }
                        if let bannerModel = [HWHomeInfoBannerModel].deserialize(from: result ,designatedPath: ".banners") {
                            dataModel.banners = bannerModel as? [HWHomeInfoBannerModel]
                        }
//                        if let bannerModel = [HWHomeInfoBannerModel].deserialize(from: result ,designatedPath: ".banners") {
//                            dataModel.banners = bannerModel as? [HWHomeInfoBannerModel]
//                        }
                        if let shequ_id = resultDic["shequ_id"] as? String {
                            dataModel.shequ_id = shequ_id
                        }
                        success(dataModel)
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 首页推荐
    func getNewHomeRecommend(p:Int,success:@escaping (_ :HWNewHomeModel) -> Void, failure:@escaping(_ :String)->Void){

        let parameters  = [
            "p":p
        ] as [String : Any]
        
        AF.request(URL(string: URL_NewHomeRecommend)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        let dataModel = HWNewHomeModel()
                        if let itemModel = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".data") {
                            dataModel.data = itemModel as? [HWNewHomeGameModel]
                        }
                        if let bannerModel = [HWHomeInfoBannerModel].deserialize(from: result ,designatedPath: ".slide") {
                            dataModel.slide = bannerModel as? [HWHomeInfoBannerModel]
                        }
                        if let newgame_top = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".newgame_top") {
                            dataModel.newgame_top = newgame_top as? [HWNewHomeGameModel]
                        }
                        if let tuijian = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".tuijian") {
                            dataModel.tuijian = tuijian as? [HWNewHomeGameModel]
                        }
                        if let remen = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".remen") {
                            dataModel.remen = remen as? [HWNewHomeGameModel]
                        }
                        if let newgame_later = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".newgame_later") {
                            dataModel.newgame_later = newgame_later as? [HWNewHomeGameModel]
                        }
                        if let gongneng = [HWNewHomeGameModel].deserialize(from: result ,designatedPath: ".gongneng") {
                            dataModel.gongneng = gongneng as? [HWNewHomeGameModel]
                        }
                        success(dataModel)
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 某游戏社区攻略
    func getStrategyInfo(shequId: String,p:Int,success:@escaping (_ :HWStrategyModel) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "id":shequId,
            "p":p
        ] as [String : Any]
        AF.request(URL(string: URL_StrategyInfo)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        let dataModel = HWStrategyModel()
                        if let itemModel = [HWGameCommunityListModel].deserialize(from: result ,designatedPath: ".data") {
                            dataModel.data = itemModel as? [HWGameCommunityListModel]
                        }
                        if let bannerModel = [HWStrategyBlockModel].deserialize(from: result ,designatedPath: ".blocks") {
                            dataModel.blocks = bannerModel as? [HWStrategyBlockModel]
                        }
                        success(dataModel)
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 资讯评论列表
    func getInfoCommitList(infoId: String,p:Int,success:@escaping (_ :[HWInfoCommentListModel]) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "id":infoId,
            "p":p
        ] as [String : Any]
        AF.request(URL(string: URL_InfoCommitList)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    if resultDic["code"] as? Int == 1 {
                        print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                        if let models = [HWInfoCommentListModel].deserialize(from: result ,designatedPath: ".data") {
                            
                            success(models as! [HWInfoCommentListModel])
                            
                        }else{
                            failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                        }
                        
                    } else if resultDic["code"] as? Int == 100 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else {
                        print("请求失败--原因:\(resultDic["message"] ?? "请求失败--未知原因")")
                        failure(resultDic["message"] as? String ?? "")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 提交资讯评论
    func sendInfoCommit(infoId: String, pid: String,content: String,success:@escaping (_:String) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "id":infoId,
            "pid":pid,
            "content": content
        ] as [String : Any]
        
        AF.request(URL(string: URL_InfoCommitAdd)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 资讯/资讯评论 点赞
    func infoLike(type: String, id: String,success:@escaping (_:String) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "type":type,
            "id":id,
        ] as [String : Any]
        
        AF.request(URL(string: URL_InfoLike)!, method: .post, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
    
    /// 资讯收藏
    func infoCollect(id: String,success:@escaping (_:String) -> Void, failure:@escaping(_ :String)->Void){
        tStr = "\(WMUtil.getTimeSp())\(WMUtil.getRandomNumber(101, to: 998))"
        uid = HWLocallyStoredData.getLoginUserID()
        let parameters  = [
            "uid":uid,
            "t":tStr,
            "sign":encrySign(),
            "ios":"1",
            "member_id":HWLocallyStoredData.getCode(),
            "news_id":id,
        ] as [String : Any]
        
        AF.request(URL(string: URL_InfoCollect)!, method: .get, parameters: parameters, headers: headers()).responseString { (responses) in
            if responses.value != nil {
                let result:String = responses.value ?? ""
                if result != "" {
                    let resultDic = HWUniversal.JSONStringToDictionary(jsonString: result)
                    print("***********\(HWUniversal.JSONStringToDictionary(jsonString: result))")
                    if resultDic["code"] as! Int == 1 {
                        success(resultDic["message"] as! String)
                            
                    } else if resultDic["code"] as? Int == 404 {
                        HWUniversal.reLogin(message: (resultDic["message"] as? String) ?? "")
                    }else{
                        failure("\(resultDic["message"] ?? "请求失败--未知原因")")
                    }
                }else {
                    print("没有获取到数据")
                    failure("")
                }
            }else {
                print("获取数据失败")
                failure("")
            }
        }
    }
}
